home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir36 / ask_dos.zip / ASK.LST < prev    next >
File List  |  1994-03-05  |  17KB  |  429 lines

  1. Turbo Assembler     Version 3.1        03/05/94 15:17:09        Page 1
  2. ask.asm
  3.  
  4.  
  5.  
  6.       1
  7.       2                     ; *************************************************************************
  8.       3                     ; *      Date: March 31, 1992     Use: Interactive    Batch Processing.      *
  9.       4                     ; *                                       *
  10.       5                     ; *         Written by: Patrick Whittle  (519)    945-7596           *
  11.       6                     ; *         Revised to .COM format    March 5, 1994               *
  12.       7                     ; *************************************************************************
  13.       8
  14.       9          =000D             CR          EQU 0Dh
  15.      10          =000A             LF          EQU 0Ah
  16.      11          =0020             SPACE    EQU 20h
  17.      12
  18.      13                     comGrp   GROUP dSeg1, dSeg2, cSeg
  19.      14
  20.      15    0000                 cSeg     SEGMENT WORD 'CODE'         ; Give names to our segments.
  21.      16    0000                 cSeg     ENDS
  22.      17    0000                 dSeg1    SEGMENT WORD PUBLIC 'DATA'
  23.      18    0000                 dSeg1    ENDS
  24.      19    0000                 dSeg2    SEGMENT WORD PUBLIC 'DATA'
  25.      20    0000                 dSeg2    ENDS
  26.      21
  27.      22    0000                 dSeg1    SEGMENT         ; Data segment 1 for initialized data.
  28.      23                     ;
  29.      24    0000  42 61 74 63 68 20    45+  MESSAGE  DB 'Batch    Enhancer, written by Patrick Whittle, (519) 945-7596.',    CR, LF,    CR, LF
  30.      25          6E 68 61 6E 63 65    72+
  31.      26          2C 20 77 72 69 74    74+
  32.      27          65 6E 20 62 79 20    50+
  33.      28          61 74 72 69 63 6B    20+
  34.      29          57 68 69 74 74 6C    65+
  35.      30          2C 20 28 35 31 39    29+
  36.      31          20 39 34 35 2D 37    35+
  37.      32          39 36 2E 0D 0A 0D    0A
  38.      33    003F  55 53 41 47 45 3A    0D+          DB 'USAGE:', CR, LF
  39.      34          0A
  40.      35    0047  09 41 53 4B 20 5B    50+          DB 09h, 'ASK [Prompt to display]', CR, LF
  41.      36          72 6F 6D 70 74 20    74+
  42.      37          6F 20 64 69 73 70    6C+
  43.      38          61 79 5D 0D 0A
  44.      39    0061  09 41 53 4B 20 5B    2F+          DB 09h, 'ASK [/?]', CR, LF, CR, LF
  45.      40          3F 5D 0D 0A 0D 0A
  46.      41    006E  52 65 74 75 72 6E    73+          DB 'Returns DOS errorlevel.', CR,    LF, 00h
  47.      42          20 44 4F 53 20 65    72+
  48.      43          72 6F 72 6C 65 76    65+
  49.      44          6C 2E 0D 0A 00
  50.      45                     ;
  51.      46    0088  28 59 20 6F 72 20    4E+  PROMPT   DB '(Y or    N)? ', 00h
  52.      47          29 3F 20 00
  53.      48    0093  59 45 53 00         YES      DB 'YES',    00h
  54.      49    0097  4E 4F 00             NO          DB 'NO', 00h
  55.      50                     ;
  56.      51    009A  0D 0A 3C 42 72 65    61+  ctrlText DB CR, LF, '<Break>', CR,    LF, 00h
  57.      52          6B 3E 0D 0A 00
  58.      53    00A6                 dSeg1    ENDS
  59.      54
  60.      55    0000                 dSeg2    SEGMENT         ; Data segment 2 for un-initialized data.
  61.      56                     ;
  62.      57    0000  ??             errorlevel          DB ?
  63. Turbo Assembler     Version 3.1        03/05/94 15:17:09        Page 2
  64. ask.asm
  65.  
  66.  
  67.  
  68.      58    0001  ????             origSegment      DW ?
  69.      59    0003  ????             origOffset          DW ?
  70.      60                     ;
  71.      61    0005                 dSeg2    ENDS
  72.      62
  73.      63    0000                 cSeg     SEGMENT
  74.      64
  75.      65                       ASSUME   cs:comGrp, ds:comGrp, es:comGrp, ss:comGrp
  76.      66
  77.      67                       ORG 100h            ; Start of CS and DS
  78.      68
  79.      69    0100                 Main:
  80.      70    0100  E8 009A             call    grabCommandline           ; Command-line tail given?
  81.      71    0103  E3 2B             jcxz    sendInstruction           ; If    not, send out prompt.
  82.      72
  83.      73    0105  81 3C 3F2F         cmp    WORD PTR [si], '?/'
  84.      74    0109  74 2A             je    sendHelp
  85.      75    010B  8B DE             mov    bx, si            ; SI contains pointer to cmd-line argument.
  86.      76    010D  E8 006B             call    dispString        ; Display user supplied string.
  87.      77
  88.      78    0110                 ContinueMain:
  89.      79    0110  E8 00DC             call    getIntVector
  90.      80    0113  BA 01C5r             lea    dx, ctrlBreakHandler
  91.      81    0116  E8 00D0             call    setIntVector
  92.      82    0119  E8 0026             call    Validate        ; Compare inputed keys with    Y and N.
  93.      83
  94.      84    011C                 Stop:
  95.      85    011C  1E             push    ds
  96.      86    011D  8B 16 0003r         mov    dx, comGrp:origOffset
  97.      87    0121  8E 1E 0001r         mov    ds, comGrp:origSegment
  98.      88    0125  E8 00C1             call    setIntVector
  99.      89    0128  1F             pop    ds
  100.      90
  101.      91    0129                 DOSexit:
  102.      92    0129  B4 4C             mov    ah, 4Ch               ; Program Terminate with    errorlevel.
  103.      93    012B  A0 0000r             mov    al, comGrp:errorlevel
  104.      94    012E  CD 21             int    21h
  105.      95
  106.      96    0130                 sendInstruction:
  107.      97    0130  E8 0041             call    OutPut
  108.      98    0133  EB DB             jmp    ContinueMain        ; Proceed and validate input.
  109.      99
  110.     100    0135                 sendHelp:
  111.     101    0135  BB 0000r             lea    bx, MESSAGE
  112.     102    0138  E8 0040             call    dispString
  113.     103    013B  C6 06 0000r 00         mov    comGrp:errorlevel, 00h
  114.     104    0140  EB E7             jmp    DOSexit
  115.     105
  116.     106                     ;---------------------------
  117.     107
  118.     108    0142                 Validate PROC NEAR
  119.     109    0142  E8 0045             call    AcceptChar
  120.     110    0145  3C 59             cmp    al, 'Y'            ; Is this the "Y" character?
  121.     111    0147  74 0C             je    YWasTyped
  122.     112    0149  3C 4E             cmp    al, 'N'            ; Is this the "N" character?
  123.     113    014B  74 18             je    NWastyped
  124.     114    014D  E8 0042             call    Cr_Lf
  125. Turbo Assembler     Version 3.1        03/05/94 15:17:09        Page 3
  126. ask.asm
  127.  
  128.  
  129.  
  130.     115    0150  E8 0021             call    OutPut            ; Conditions not met.
  131.     116    0153  EB ED             jmp    Validate        ; Unconditional jump.
  132.     117
  133.     118    0155                 YWasTyped:
  134.     119    0155  BB 0093r             lea    bx, comGrp:YES        ; Load Effective Address into BX.
  135.     120    0158  E8 0020             call    dispString
  136.     121    015B  E8 0034             call    Cr_Lf
  137.     122    015E  C6 06 0000r 00         mov    comGrp:errorlevel, 00h       ; Set DOS errorlevel    to zero.
  138.     123    0163  EB 0E             jmp    CharactersFine
  139.     124
  140.     125    0165                 NWasTyped:
  141.     126    0165  BB 0097r             lea    bx, comGrp:NO
  142.     127    0168  E8 0010             call    dispString
  143.     128    016B  E8 0024             call    Cr_Lf
  144.     129    016E  C6 06 0000r 01         mov    comGrp:errorlevel, 01h       ; Set DOS errorlevel    to one.
  145.     130
  146.     131    0173                 CharactersFine:
  147.     132    0173  C3             ret
  148.     133
  149.     134    0174                 Validate ENDP
  150.     135
  151.     136    0174                 Output PROC NEAR
  152.     137    0174  BB 0088r             lea    bx, PROMPT
  153.     138    0177  E8 0001             call    dispString
  154.     139    017A  C3             ret                ; Return to    calling    module.
  155.     140
  156.     141    017B                 Output ENDP
  157.     142
  158.     143    017B                 dispString    PROC NEAR
  159.     144    017B  B4 02             mov    ah, 02h
  160.     145
  161.     146    017D                 sendPrompt:
  162.     147    017D  80 3F 00             cmp    BYTE PTR [bx], 00h
  163.     148    0180  74 07             je    promptDone
  164.     149    0182  8A 17             mov    dl, BYTE PTR [bx]
  165.     150    0184  CD 21             int    21h
  166.     151    0186  43             inc    bx
  167.     152    0187  EB F4             jmp    sendPrompt
  168.     153
  169.     154    0189                 promptDone:
  170.     155    0189  C3             ret
  171.     156
  172.     157    018A                 dispString    ENDP
  173.     158
  174.     159    018A                 AcceptChar    PROC NEAR
  175.     160    018A  B4 08             mov    ah, 08            ; Accept character function.
  176.     161    018C  CD 21             int    21h
  177.     162    018E  E8 004D             call    upCase
  178.     163    0191  C3             ret                ; Return to    calling    module.
  179.     164
  180.     165    0192                 AcceptChar    ENDP
  181.     166
  182.     167    0192                 Cr_Lf PROC    NEAR
  183.     168    0192  B4 02             mov    ah, 02h
  184.     169    0194  B2 0D             mov    dl, CR
  185.     170    0196  CD 21             int    21h
  186.     171    0198  B2 0A             mov    dl, LF
  187. Turbo Assembler     Version 3.1        03/05/94 15:17:09        Page 4
  188. ask.asm
  189.  
  190.  
  191.  
  192.     172    019A  CD 21             int    21h
  193.     173    019C  C3             ret                ; Return to    calling    module.
  194.     174
  195.     175    019D                 Cr_Lf ENDP
  196.     176
  197.     177    019D                 grabCommandline PROC NEAR
  198.     178                     ;
  199.     179                     ; Any command-line    parameters supplied by the user    will be    passed by DOS into
  200.     180                     ; the executing programs PSP (Program Segment Prefix) area.  The default PSP
  201.     181                     ; area in a program, weather in .EXE format or .COM format, is between offset
  202.     182                     ; 0000 and    0100h of the programs data segment. Since a program in .COM format
  203.     183                     ; has its code, data, and stack stored in the same    segment    of memory
  204.     184                     ; (i.e. CS=DS=SS respectively) it is necessary that the code of .COM programs
  205.     185                     ; always starts at    offset 0100h (see ORG directive    at start of this program).
  206.     186                     ;
  207.     187                     ; This PROCedure uses SI register to access the PSP making    use of a flag set
  208.     188                     ; by DOS at offset    80h.  This single byte indicates weather a command-line
  209.     189                     ; argument    was supplied or    not.  If the value at offset 80h is zero, then
  210.     190                     ; no command-line argument    was supplied.  If the value is non-zero, the
  211.     191                     ; contents    of offset 80h will hold    a byte count for the supplied argument.
  212.     192                     ;
  213.     193                     ; In this procedure, the CX register will receive a copy of the byte at
  214.     194                     ; offset 80h to be    used in    calculating the    end address of the string.  All
  215.     195                     ; preceding, and trailing spaces will be discarded.
  216.     196                     ;
  217.     197                     ; Inputs:
  218.     198                     ;          None
  219.     199                     ;
  220.     200                     ; Output:
  221.     201                     ;          si - Pointer to start of user supplied string.
  222.     202                     ;          cx - zero    if no command-line argument given.
  223.     203                     ;
  224.     204                     ; Registers modified:
  225.     205                     ;          cx, si
  226.     206                     ;
  227.     207    019D  33 C9             xor    cx, cx             ; Zero out    cx register.
  228.     208    019F  BE 0080             mov    si, 80h
  229.     209    01A2  80 3C 00             cmp    BYTE PTR [si], 00h
  230.     210    01A5  74 1D             je    grabDone         ; If byte at offset 80h is    0 then there were
  231.     211                                     ;      no arguments.
  232.     212    01A7  8A 0C             mov    cl, BYTE PTR [si]    ; Move byte pointed to by SI into CL register.
  233.     213
  234.     214    01A9                 findNonblank:
  235.     215    01A9  46             inc    si
  236.     216    01AA  80 3C 20             cmp    BYTE PTR [si], SPACE
  237.     217    01AD  75 02             jne    startFound
  238.     218    01AF  E2 F8             loop    findNonblank         ; Assume length of    argument is one    less now
  239.     219                                     ; as loop decrements CX register.
  240.     220    01B1                 startFound:
  241.     221    01B1  E3 11             jcxz    grabDone         ; If CX is    zero then the user has supplied
  242.     222                                     ;      a string of spaces and just pressed ┘
  243.     223    01B3  56             push    si             ; Save start of argument.
  244.     224    01B4  03 F1             add    si, cx             ; To point    to end.
  245.     225
  246.     226    01B6                 testForTrailingBlank:
  247.     227    01B6  4E             dec    si
  248.     228    01B7  80 3C 20             cmp    BYTE PTR [si], SPACE
  249. Turbo Assembler     Version 3.1        03/05/94 15:17:09        Page 5
  250. ask.asm
  251.  
  252.  
  253.  
  254.     229    01BA  75 02             jne    terminateArgument
  255.     230    01BC  E2 F8             loop    testForTrailingBlank      ; Remove unwanted spaces.
  256.     231
  257.     232    01BE                 terminateArgument:
  258.     233    01BE  C7 44 01 0020         mov    WORD PTR [si+1], 0020h      ; Add    space and ensure string    is ASCIIZ.
  259.     234    01C3  5E             pop    si
  260.     235
  261.     236    01C4                 grabDone:
  262.     237    01C4  C3             ret
  263.     238
  264.     239    01C5                 grabCommandline ENDP
  265.     240
  266.     241    01C5                 ctrlBreakHandler PROC NEAR
  267.     242                     ;
  268.     243                     ; This PROCedure is the replacement interrupt handler for int 23h - the
  269.     244                     ; Ctrl-Break interrupt.  Regardless where the machine is currently    executing
  270.     245                     ; in memory, the Ctrl-C interrupt will instantly force execution to branch
  271.     246                     ; to this area. The int 23h handler will be restored when ASK.COM terminates.
  272.     247                     ;
  273.     248                     ; The value of all    segment    registers will be unchanged when an interrupt is
  274.     249                     ; encountered.  Since this    program    is not a TSR (Terminate    and Stay Resident)
  275.     250                     ; we don't    need to    worry about initializing DS to point to    our data for
  276.     251                     ; example,    or any other segment registers.
  277.     252                     ;
  278.     253                     ; If this were a TSR program or device driver on the other    hand, segment
  279.     254                     ; registers would not contain values reflecting the location of code, data,
  280.     255                     ; etc., for ASK.COM, they would contain values that were part of some other
  281.     256                     ; executing program at the    time of    the interrupt.
  282.     257                     ;
  283.     258                     ; The way the internal interrupt vectors are designed on Intel machines is
  284.     259                     ; such that only the CS:IP    registers (code    segment:instruction pointer) are
  285.     260                     ; modified    when a certain interrupt is encountered, and a FAR return address
  286.     261                     ; is then pushed onto the stack (segment:offset = current execution address
  287.     262                     ; of interrupted program).     It is up to the "interruptor" (i.e. the device
  288.     263                     ; driver, or TSR program) to first    set up segment registers to point to its
  289.     264                     ; needed data, stack etc.,    and when finished, restore CS:IP with an iret
  290.     265                     ; instruction once    the service requested of the device driver is complete.
  291.     266                     ;
  292.     267                     ; Output:
  293.     268                     ;          Program terminates with DOS errorlevel 2
  294.     269                     ;
  295.     270                     ; Registers modified:
  296.     271                     ;          ax, bx, cx
  297.     272                     ;
  298.     273    01C5  8C C8             mov    ax, cs               ; The next three    move intstructions are
  299.     274    01C7  8E D8             mov    ds, ax               ; not needed in the context of this program,
  300.     275    01C9  8E C0             mov    es, ax               ; but are included for demonstration.
  301.     276    01CB  C6 06 0000r 02         mov    comGrp:errorlevel, 02h
  302.     277    01D0  BB 009Ar             lea    bx, comGrp:ctrlText
  303.     278    01D3  E8 FFA5             call    dispString
  304.     279
  305.     280    01D6  B8 0C00             mov    ax, 0C00h           ; Flush keyboard    buffer.
  306.     281    01D9  CD 21             int    21h
  307.     282    01DB  E9 FF3E             jmp    Stop
  308.     283
  309.     284    01DE                 ctrlBreakHandler ENDP
  310.     285
  311. Turbo Assembler     Version 3.1        03/05/94 15:17:09        Page 6
  312. ask.asm
  313.  
  314.  
  315.  
  316.     286    01DE                 upCase PROC NEAR
  317.     287                     ;
  318.     288                     ; This function returns the corresponding upper-case letter for
  319.     289                     ; the lower-case letter passed in al.
  320.     290                     ;
  321.     291                     ; Input:
  322.     292                     ;          al   - contains the ASCII    value for a lower-case letter
  323.     293                     ; Output:
  324.     294                     ;          al   - contains the ASCII    value for the corresponding upper-case
  325.     295                     ;             letter.
  326.     296                     ;
  327.     297                     ; Registers modified:
  328.     298                     ;          al
  329.     299                     ;
  330.     300                     ; Convert the letter in AL    to upper-case.
  331.     301                     ;
  332.     302    01DE  3C 61             cmp    al, 'a'
  333.     303    01E0  72 06             jb    upcas1
  334.     304    01E2  3C 7A             cmp    al, 'z'
  335.     305    01E4  77 02             ja    upcas1
  336.     306    01E6  2C 20             sub    al, 20h
  337.     307
  338.     308    01E8                 upcas1:
  339.     309    01E8  C3             ret
  340.     310
  341.     311    01E9                 upCase ENDP
  342.     312
  343.     313    01E9                 setIntVector PROC NEAR
  344.     314                     ;
  345.     315                     ; DX register must    be initialized first before calling.
  346.     316                     ;
  347.     317    01E9  B8 2523             mov    ax, 2523h
  348.     318    01EC  CD 21             int    21h
  349.     319    01EE  C3             ret
  350.     320
  351.     321    01EF                 setIntVector ENDP
  352.     322
  353.     323    01EF                 getIntVector PROC NEAR
  354.     324    01EF  06             push    es
  355.     325    01F0  B8 3523             mov    ax, 3523h          ;    23 is ctrl-break location in interrupt
  356.     326    01F3  CD 21             int    21h              ;    vector table.
  357.     327
  358.     328    01F5  8C 06 0001r         mov    WORD PTR comGrp:origSegment, es
  359.     329    01F9  89 1E 0003r         mov    WORD PTR comGrp:origOffset, bx
  360.     330    01FD  07             pop    es
  361.     331    01FE  C3             ret
  362.     332
  363.     333    01FF                 getIntVector ENDP
  364.     334
  365.     335    01FF                 cSeg     ENDS
  366.     336
  367.     337                     END      Main
  368. Turbo Assembler     Version 3.1        03/05/94 15:17:09        Page 7
  369. Symbol Table
  370.  
  371.  
  372.  
  373.  
  374. Symbol Name              Type     Value
  375.  
  376. ??DATE                  Text     "03/05/94"
  377. ??FILENAME              Text     "ask      "
  378. ??TIME                  Text     "15:17:09"
  379. ??VERSION              Number 030A
  380. @CPU                  Text     0101H
  381. @CURSEG                  Text     CSEG
  382. @FILENAME              Text     ASK
  383. @WORDSIZE              Text     2
  384. ACCEPTCHAR              Near     CSEG:018A
  385. CHARACTERSFINE              Near     CSEG:0173
  386. CONTINUEMAIN              Near     CSEG:0110
  387. CR                  Number 000D
  388. CR_LF                  Near     CSEG:0192
  389. CTRLBREAKHANDLER          Near     CSEG:01C5
  390. CTRLTEXT              Byte     DSEG1:009A
  391. DISPSTRING              Near     CSEG:017B
  392. DOSEXIT                  Near     CSEG:0129
  393. ERRORLEVEL              Byte     DSEG2:0000
  394. FINDNONBLANK              Near     CSEG:01A9
  395. GETINTVECTOR              Near     CSEG:01EF
  396. GRABCOMMANDLINE              Near     CSEG:019D
  397. GRABDONE              Near     CSEG:01C4
  398. LF                  Number 000A
  399. MAIN                  Near     CSEG:0100
  400. MESSAGE                  Byte     DSEG1:0000
  401. NO                  Byte     DSEG1:0097
  402. NWASTYPED              Near     CSEG:0165
  403. ORIGOFFSET              Word     DSEG2:0003
  404. ORIGSEGMENT              Word     DSEG2:0001
  405. OUTPUT                  Near     CSEG:0174
  406. PROMPT                  Byte     DSEG1:0088
  407. PROMPTDONE              Near     CSEG:0189
  408. SENDHELP              Near     CSEG:0135
  409. SENDINSTRUCTION              Near     CSEG:0130
  410. SENDPROMPT              Near     CSEG:017D
  411. SETINTVECTOR              Near     CSEG:01E9
  412. SPACE                  Number 0020
  413. STARTFOUND              Near     CSEG:01B1
  414. STOP                  Near     CSEG:011C
  415. TERMINATEARGUMENT          Near     CSEG:01BE
  416. TESTFORTRAILINGBLANK          Near     CSEG:01B6
  417. UPCAS1                  Near     CSEG:01E8
  418. UPCASE                  Near     CSEG:01DE
  419. VALIDATE              Near     CSEG:0142
  420. YES                  Byte     DSEG1:0093
  421. YWASTYPED              Near     CSEG:0155
  422.  
  423. Groups & Segments          Bit Size Align  Combine Class
  424.  
  425. COMGRP                  Group
  426.   CSEG                  16  01FF Word      none      CODE
  427.   DSEG1                  16  00A6 Word      Public  DATA
  428.   DSEG2                  16  0005 Word      Public  DATA
  429.